<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 准备好容器 -->
    <div id="test">
    </div>
</body>
<!-- 引入依赖 引入的时候，必须就按照这个步骤-->
<script src="../React-js/react.development.js" type = "text/javascript"></script>
<script src = "../React-js/react-dom.development.js" type = "text/javascript"></script>
<script src="../React-js/babel.min.js" type="text/javascript"></script>


<script type="text/babel">
    class A extends React.Component{
        state = {carName:'奔驰'}
        changeCar = ()=>{
            this.setState({carName:'奔驰1'})
        }
        render(){
            return(
                <div>
                    <div>A</div>
                    <button onClick={this.changeCar}>换车</button>
                    <B carName={this.state.carName}/>
                </div>
            )
        }
    }
    
    class B extends React.Component{
        // 组件将要接收新的props的钩子
        componentWillReceiveProps(props){
            console.log('B-componentWillReceiveProps',props)
        }
        // 控制组件更新的阀门
        shouldComponentUpdate(){
            console.log('B-shouldComponentUpdate')
            return true;
        }
        // 组件将要更新
        componentWillUpdate(){
            console.log('B-componentWillUpdate')
        }
        // 组件更新完毕
        componentDidUpdate(){
            console.log('B-componentDidUpdate')
        }
        render(){
            return(
                <div>B,车：{this.props.carName}</div>
            )
        }
    }

    ReactDOM.render(<A/>,document.getElementById("test"))
</script>
</html>